﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Motoball.screenmanager;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Motoball.Paddles;

namespace Motoball.screens
{
    class SingleplayerGameplayScreen:GameplayScreen
    {
        public AIPlayer aiPlayer;

        public SingleplayerGameplayScreen(string screenName)
            : base(screenName)
        {
            aiPlayer = new AIPlayer(Color.Crimson, this);
            aiPlayer.OtherPaddle = player1;
        }
        protected override bool BallToPaddleHandling(Paddle player)
        {
            if (player.PlayerIndex == 0)
            {
                if (base.BallToPaddleHandling(player))
                {
                    aiPlayer.ballHunting = true;
                    aiPlayer.CalcTarget(ball.Position, ball.Direction);
                    return true;
                }
            }
            else
            {
                if (Vector3.Distance(aiPlayer.World.Translation, ball.Position) <
                        aiPlayer.MaxPaddleDistance && ball.PlayerFlag)
                {
                    ball.Reflect(aiPlayer);
                    aiPlayer.paddleContent.ballHit = true;
                    aiPlayer.ballHunting = false;
                    aiPlayer.RandomAggressiveness(ball.Position, ball.Direction);
                    ball.Speed += 0.5f;
                    return true;
                }
            }
            return false;
        }
        public override void SetElementsActive(bool active)
        {
            aiPlayer.active = !active;
            base.SetElementsActive(active);
        }
        
        public override void SetToActive()
        {
            aiPlayer.Color = player2.Color;
            player2 = aiPlayer;
            //memo: debug in mp
            player1.OtherPaddle = aiPlayer;
            base.SetToActive();
        }

        /// <summary>
        /// memo:...try to find out what i thought at creating this method-head ^^
        /// </summary>
        public void Init()
        {

        }
    }
}
